

* TESTS FOR BAD CONTROLS

* ESTIMATE LIN REGS FOR EACH DEP VR AND QUARTER WITH AND WITHOUT POTENTIALLY ENDOGENOUS CONTROL VARIABLES (BAD CONTROLS)
* TEST THAT COEFFS ON ASSIGNMENT DUMMY ARE THE SAME (CFR. ANGRIST-PISCHKE)
* FIG D1 PLOTS DISTR OF PVALUES OF TEST OF EQUALITY OF COEFFS

quietly{
use WorkingData, clear

* UNWEIGHTED - TRIMMED SAMPLE

mat def BC=J($ntrims,13,.)

set more off

local r = 1
forvalues q=$firsttrim/$lasttrim{
	local c = 1
	mat BC[$_r,$_c] = $_q
	local c = $_c + 1 
	foreach y in it6all it12all it24all it48all dprez F1DPZ F2DPZ F4DPZ F1LAD F2LAD F3LAD F4LAD{
		count if $_y !=. & dp==$_q
		if r(N)!=0{
		qui reg $_y treatment dpre i.dim i.area i.setton5 if trims !=1 & dp==$_q
		estimate store relong
		qui reg $_y treatment i.area i.setton5 if trims !=1 & dp==$_q
		estimate store reshort
		qui suest relong reshort, vce(robust)
		test [relong_mean]treatment_old=[reshort_mean]treatment_old
		mat BC[$_r,$_c]=r(p)
		}
		local c = $_c + 1
	}
	local r = $_r + 1
}

* ************* GENERATE FIG D1 ***************

drop _all
svmat BC

rename BC1 dp
reshape long BC, i(dp) j(v)
replace v=v-1
gen 	 z=1 if BC<0.01
replace  z=2 if BC<0.05 & z==.
replace  z=3 if BC<0.1 & z==.
replace  z=4 if BC<0.2 & z==.
replace  z=5 if BC>=0.2 & BC!=.
drop if BC==.
lab def lz 0 " " 1 "<0.01" 2 "<0.05" 3 "<0.10" 4 "<0.20" 5 ">=0.20"
lab val z lz

hist z, freq d xla(0(1)5,valuelab notick) xti("p-value") yla(0(25)350, angle(0)) yti("") color(blue) barw(0.8) graphregion(c(white))
graph export FigBadControl_D1.eps, replace
* ************* GENERATE FIG D1 : END ***************

}

* ========================================================
* PRINT TO LOG DATA UNDERLYING FIG D1

collapse (count) BC, by(z)
lab var BC "Frequency"
lab var z "pval"
* ***********************
* ***** DATA FIG D1 *****
* ***********************
list z BC 
